<?php

declare (strict_types=1);

namespace App\Model\GuildManage;

use App\Constants\GuildCode;
use App\Model\Guild\GuildBase;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;

/**
 */
class GuildBalanceDaily extends GuildBase
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'guild_balance_daily';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];

    /**
     * 根据工会id获取当日数据
     * @param $guildId
     * @return Builder|Model|object|null
     */
    public function getDateColumnByGuildId($guildId)
    {
        return $this->where('dt', date('Y-m-d', strtotime("-1 day")))
            ->where('guild_manage_id', $guildId)
            ->first();
    }

    /**
     * 获取审核数据
     * @param $guildId
     * @return Builder|Model|object|null
     */
    public function getAuditInfoByGuildId($guildId)
    {
        $auditDay = GuildCode::AUDIT_DAY + 1;

        return $this
            ->where('dt', date('Y-m-d', strtotime("-{$auditDay} day")))
            ->where('guild_manage_id', $guildId)
            ->first();
    }
}